import { CDState, PrepareState, Skill, SkillEvent, SpellState } from "../Skill";
import Unit from "../Unit";
/**
 * 技能瞄准准备状态
 */
export class AimSkillPrepareState extends PrepareState {
    public onEnter(){
        this.onUpdate = null;
        this.onQuit = null;
        this.fsm.cd = 0;
        this.fsm.sendEvent(SkillEvent.Prepare);
    }
}
/**
 * 技能瞄准施放状态
 */
export class AimSkillSpellState extends SpellState {
    public onEnter(){
        this.fsm.sendEvent(SkillEvent.Spell);
       this.fsm.changeState('cd');
    }
}
/**
 * 技能瞄准CD状态
 */
export class AimSkillCDState extends CDState {
    public onEnter(){
        this.fsm.sendEvent(SkillEvent.CD);
    }
}
let statetype = { AimSkillPrepareState, AimSkillSpellState, AimSkillCDState }
/**
 * 瞄准技能
 */
export default class AimSkill extends Skill {

    /**
     * 瞄准单位
     */
    aimUnit: Unit;
    /**
     * 距离
     */
    distance: number;
    public constructor(skillData) {
        super(skillData);
    }
    
    public init() {
        for (const key in this.skillData.states) {
            let state = this.skillData.states[key];
            let s = new statetype[key](this, state.name);
            this.states.set(state.name, s);
        }

    }
    
    public sendEvent (){

    }
    /**
     * 进入CD
     */
    public inCD(){

    }
    
    public checkCanSpell(): boolean {
        return this.unit.pos.sub(this.aimUnit.pos).len() <= this.distance && this.cd <= 0;
    }

}  